<template>
  <div class="pingjia">
    <div class="pingjiaWrap">
      <div class="scoreWrap">
        <span>评价课程</span>
        <score :score-no.sync="scoreNo" :disabled="false"></score>
      </div>
      <div class="iptWrap clear">
        <textarea class="fl" placeholder="点评一下课程吧！" v-model="content"></textarea>
        <a class="handel fl"></a>
      </div>
      <div class="picWrap clear">
        <div class="imgWrap" v-for="img in imgs" track-by="$index">
          <img :src="img" />
          <a class="del" @click="delImg(img)">&#xe612;</a>
        </div>
      </div>
      <a class="g-submit" @click="doSubmit">确定</a>
    </div>
  </div>
</template>
<script type="text/babel">
  import {submit} from '../factory/evaluate';
  export default {
    name: 'index',
    components: {
      score: require('../components/score')
    },
    data () {
      return {
        scoreNo: 0,
        content: '',
        imgs: ['http://xqproduct.xiangqu.com/FlLJRvAZhKWhPTqVyf5lM3QUOdNe', 'http://xqproduct.xiangqu.com/FlLJRvAZhKWhPTqVyf5lM3QUOdNe']
      };
    },
    created () {
      // let that = this;
      this.$dispatch('alert.close');
    },
    methods: {
      delImg (img) {
        this.$dispatch('alert', '是否删除改图片?', () => {
          this.imgs.$remove(img);
        });
      },
      doSubmit () {
        let that = this;
        let ajaxData = {
          id: that.$route.query.id,
          content: that.content,
          imgs: that.imgs,
          score: that.scoreNo
        };
        submit(ajaxData).then(res => {
          if (!res.iserror) {
            that.$dispatch('alert', '操作成功~');
          }
        });
      }
    }
  };
</script>
